package com.test.activity;

import com.test.activity.R.color;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.Editable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.EditText;

public class MyEditText extends EditText {

	private final String PACKAGE_NAME = "com.test.activity";
	private int mColor;
	public int bottom = 0;

	public MyEditText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		getPropertyOfXml(context, attrs);
	}

	public MyEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		getPropertyOfXml(context, attrs);
	}

	public MyEditText(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	private void getPropertyOfXml(Context context, AttributeSet attrs) {
		TypedArray ta = context.obtainStyledAttributes(attrs,
				R.styleable.MyEditText);
		this.setTextSize(ta.getDimension(R.styleable.MyEditText_text_size, 20));
	}

	@Override
	protected void onDraw(Canvas canvas) {
		int lineHeight = this.getLineHeight();
		Paint mPaint = getPaint();
		mPaint.setColor(color.gray);
		int topPadding = this.getPaddingTop();
		int leftPadding = this.getPaddingLeft();
		float textSize = getTextSize();
		setGravity(Gravity.LEFT | Gravity.TOP);
		int y = (int) (topPadding + textSize) + 15;
		if (bottom == 0) {
			bottom = y;
		}
		for (int i = 0; i < getLineCount(); i++) {
			canvas
					.drawLine(leftPadding, y, getRight() - leftPadding, y,
							mPaint);
			y += lineHeight;
		}
		canvas.translate(0, 0);
		super.onDraw(canvas);
	}

	@Override
	public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
		return new TestInputConnection(super.onCreateInputConnection(outAttrs),
				false);
	}

	@Override
	public Editable getText() {

		return super.getText();
	}
}
